package mobi.yuanshen.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 初始化核心插件
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor pageInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        pageInnerInterceptor.setMaxLimit(1000L);// 设置分页上限,最多查1000条，可选
        pageInnerInterceptor.setOverflow(true);// 可以循环查，查到最后一页时会返回第一页,可选
        // 添加分页插件
        interceptor.addInnerInterceptor(pageInnerInterceptor);
        return interceptor;
    }
}